<template>
	<view class="content" style="height: 100%;"
		:style="'background: url('+ c_imgPath + 'indexBg.png'+ ') repeat-y 0 0 / 100% auto;'">
		<view class="fixed">
			<view class="status_bar"></view>
			<view class="flex_center">
				<view class="header-left-title">
					<!-- <image :src="c_imgPath + 'logo.png'"></image> -->
					乐掏
				</view>
				<view class="title_ipt">
					<image :src="c_imgPath+'search.png'"></image>
					<input type="text" placeholder="请输入关键字" placeholder-style="color:rgba(2555,255,255,0.6)"
						confirm-type="search" v-model="keyword" @confirm="show='',loadData(1)" />
				</view>
			</view>
		</view>
		<mescroll-body ref="mescrollRef" class="valbox" @init="mescrollInit" :down="downOption" @down="downCallback"
			@up="upCallback">
			<swiper class="swiper-box" :autoplay="true" :indicator-dots="true" :circular="true">
				<swiper-item v-for="(v,i) in advert" :key='i'>
					<image class="yh_bg" :src="v.imgurl"></image>
				</swiper-item>
			</swiper>
			<image :src="c_imgPath+'xian.gif'" style="width:750rpx;height:13rpx;display: block;"></image>
			<view class="gonggao" v-if="aa && notice_list && notice_list.length>0">
				<lff-barrage ref="lffBarrage"></lff-barrage>
			</view>
			<view class="huodong">
				<view class="item" v-for="(item,index) in huodongList" :key="index" @click="toPages(item.url,index)">
					<view class="item_img">
						<image :src="c_imgPath + item.img"></image>
					</view>
					<view class="item_text">{{item.text}}</view>
				</view>
				<!-- <image :src="z_imgPath + 'cart1.png'" class="huodong_t" @click="$refs.qunliao_show.open()"></image>
				<image :src="z_imgPath + 'cart2.png?11'" class="huodong_t" @click="toNewMp()">
				</image>
				<image :src="z_imgPath + 'cart3.png'" class="huodong_t" @click="torili()"></image>
				<image :src="z_imgPath + 'cart4.png'" class="huodong_b" @click="gotoPage('/pages/user/tui-guang')">
				</image>
				<image :src="z_imgPath + 'cart5.png'" class="huodong_b" @click="gotoPage('/pages/shouye/bangdan')">
				</image> -->
			</view>

			<view class="qiehuan">
				<view @click="getlist(v.id)" v-for="(v,i) in arr" :key="i">
					<view :class="show==v.id?'xzs':'wzs'">{{v.title}}</view>
					<view class="qiehuan_line" v-if="show==v.id"> </view>
				</view>
			</view>

			<view class="qbt_con">
				<view v-for="(item,index) in listdata" :key="index" class="qbt_con_item" @click="todetails(item)"
					:style="'background: url('+ c_imgPath + 'kuang_bg.gif?1'+ ') no-repeat 0 0 / 100% 100%;'">
					<view class="item_title">{{item.title}}</view>
					<view class="item_img">
						<image :src="item.imgurl"></image>
					</view>
					<view class="item_info"
						:style="'background: url('+ c_imgPath + 'kuang_bg_bom.png'+ ') no-repeat 0 0 / 100% 100%;'">
						<view class="item_info_left">{{item.sale_stock}}/{{item.stock}}</view>
						<view class="item_info_img">
							<image :src="c_imgPath+'box.png'"></image>
						</view>
						<view class="item_info_text">{{item.join_count}}次参与</view>
						<view class="item_info_price">
							<text v-if="item.type != 5">￥</text>
							<text class="item_info_price_text" v-if="item.type == 5">{{Math.round(item.price)}}</text>
							<text class="item_info_price_text" v-else>{{item.price}}</text>
							<text v-if="item.type == 5">积分</text>
						</view>
					</view>
					<view class="item_shang">
						<text>{{item.type_name}}</text>
					</view>
					<!-- <view class="list_1">
						<image :src="item.imgurl"></image>
					</view>
					<view class="list_2">
						<view class="hang1">{{item.title}}</view>
						<view class="redu" v-if="item.join_user && item.join_user.length>0">
							<image :src="item.userinfo.headimg" v-for="(item,index) in item.join_user" :key="index"
								v-if="index<5 && item.userinfo" :style="'transform:translateX('+-index*16+'rpx'+')'">
							</image>
							<text> {{item.join_count}}次参与</text>
						</view>
						<view class="redu" v-else> 快去参与吧！ </view>
						<view class="qbt_con_item_3 flex_center">
							<view>￥ <text style="font-size: 32rpx;">{{item.price}}</text></view>
							<view class="qbt_con_item_price ">
								<text>{{item.sale_stock}}/{{item.stock}}</text>
								<image :src="z_imgPath + 'box.png'"></image>
							</view>
						</view>
					</view> -->
					<!-- <image :src="z_imgPath + 'new.png'" class="image1" v-if="index<2"></image> -->
					<!-- <image :src="z_imgPath + 'yushou.png'" class="image2" v-if="item.type==1"></image> -->
					<!-- <image :src="z_imgPath + 'yifansang.png'" class="image3" v-if="item.type==1"></image>
					<image :src="z_imgPath + 'wuxiansang.png'" class="image3" v-if="item.type==2"></image>
					<image :src="z_imgPath + 'leitaisang.png'" class="image3" v-if="item.type==3"></image>
					<image :src="z_imgPath + 'jifensang.png'" class="image3" v-if="item.type==5"></image> -->
				</view>
			</view>
		</mescroll-body>
		<!-- 群聊弹窗 -->
		<uni-popup ref="qunliao_show" type="center">
			<view class="pop" :style="'background: url('+c_imgPath+'qunliao_bg.png'+ ') no-repeat 0 0 / 100% 100%;'">
				<image :src="erweima"></image>
				<image :src="z_imgPath + 'close.png'" class="qunliao_close" @click="$refs.qunliao_show.close()">
				</image>
			</view>
		</uni-popup>
		<!-- 自定义底部 -->
		<tabbar :type="0"></tabbar>
	</view>
</template>

<script>
	import lffBarrage from '@/components/lff-barrage/lff-barrage.vue'
	import tabbar from '@/components/tabbar/tabbar.vue'
	export default {
		components: {
			lffBarrage,
			tabbar
		},
		data() {
			return {
				z_imgPath: this.$z_img + 'shouye/',
				c_imgPath: 'https://qt.yhemall.com/shouye/',
				u_imgPath: 'https://qt.yhemall.com/',
				arr: [{
						title: '新品推荐',
						id: 0
					},
					{
						title: '一番赏',
						id: 1
					},
					{
						title: '积分赏',
						id: 5
					},
					{
						title: '擂台赏',
						id: 3
					},
				],
				show: 0,
				keyword: '',
				listdata: [],
				downOption: {
					auto: false
				},
				advert: [], //轮播图
				notice_list: [], // 弹幕
				erweima: '', // 福利群
				yushou_rili: '', // 预售日历
				jump_appid: '', // 跳转的小程序id
				aa: false,
				huodongList: [{
						img: 'xrfl.png',
						text: '新人福利',
						url: ''
					},
					{
						img: 'fsjh.png',
						text: '发售计划',
						url: ''
					},
					{
						img: 'yqhy.png',
						text: '邀请好友',
						url: '/pages/user/tui-guang'
					},
					{
						img: 'zbyb.png',
						text: '周榜月榜',
						url: '/pages/shouye/bangdan'
					}
				]
			}
		},

		onUnload() {
			this.aa = false
		},
		onHide() {
			clearInterval(this.timer);
			this.aa = false
			let pages = getCurrentPages()
			// console.log(11, this.$mp.page.route)
			uni.setStorageSync('page', this.$mp.page.route)
		},
		onLoad(v) {
			if (v.pid) {
				uni.setStorageSync('pid', v.pid)
			}
			if (v.token) {
				uni.setStorageSync('token', v.token)
			}
			this.getnews()

		},
		onShow() {
			let that = this;
			this.aa = true
			setTimeout(() => {
				that.colrdo()
			}, 500)
		},

		onShareAppMessage() {
			let that = this;
			return {
				title: "快来加入乐掏~",
				imageUrl: that.advert[0].imgurl,
				path: "/pages/shouye/index?pid=" + uni.getStorageSync('userinfo').ID + '&from=' + uni.getStorageSync(
					'userinfo').from
			};
		},
		methods: {
			toPages(url, index) {
				if (index == 0) {
					this.$refs.qunliao_show.open()
				} else if (index == 1) {
					this.torili()
				} else {
					uni.navigateTo({
						url: url
					})
				}
			},
			colrdo() { //插入一条弹幕
				let that = this;
				let a = 0;
				that.timer = setInterval(function() {
					that.$refs.lffBarrage && that.$refs.lffBarrage.add({
						item: that.notice_list[a].content,
						// title: that.notice_list[a].title,
						// color: that.notice_list[a].color,
						headimg: that.notice_list[a].headimg
					});
					if (a < that.notice_list.length - 1) {
						a++;
					} else {
						a = 0
					}
				}, 5000)
			},
			toNewMp() {
				uni.navigateToMiniProgram({
					appId: uni.getStorageSync('jump_appid'), // 此为生活缴费appid
					path: 'pages/my/index?token=' + uni.getStorageSync('token'), // 此为生活缴费首页路径
					envVersion: "release",
					extraData: {
						'token': uni.getStorageSync('token')
					},
					success: res => {
						// 打开成功
						console.log("打开成功", res);
					},
					fail: err => {
						console.log(err);
					}
				})
			},
			torili() {
				uni.setStorageSync('rili', this.yushou_rili)
				this.gotoPage('/pages/shouye/rili')
			},
			getnews() {
				let that = this;
				that.req({
					url: 'index',
					success(res) {
						if (res.status == 1) {
							that.advert = res.data.advert;
							that.notice_list = res.data.new_bulletcha
							that.erweima = res.data.other.erweima
							that.yushou_rili = res.data.other.yushou_rili
							that.jump_appid = res.data.other.jump_appid
							uni.setStorageSync('jump_appid', res.data.other.jump_appid)
							uni.setStorageSync('wx_link', res.data.other.wx_link)
							uni.setStorageSync('corpid', res.data.other.corpid)
						}
					}
				})
			},
			/*下拉刷新的回调 */
			downCallback() {
				// this.mescroll.resetUpScroll()
				this.loadData(1)
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				this.loadData(page.num);
			},
			loadData(pageNo) {
				// 模拟接口
				let that = this;
				that.req({
					url: 'goods',
					data: {
						page: pageNo,
						type: that.show,
						keyword: that.keyword,
					},
					success: function(res) {
						that.mescroll.endByPage(res.data.data.length, res.data.data.last_page);
						if (pageNo == 1) {
							that.listdata = res.data.data;
						} else {
							that.listdata = that.listdata.concat(res.data.data);
						}
						console.log(that.listdata)
					}
				})
			},
			todetails(e) {
				// 无限赏
				if (e.type == 2) {
					uni.navigateTo({
						url: 'detail_wuxian?goods_id=' + e.id
					})
				} else {
					uni.navigateTo({
						url: 'detail?goods_id=' + e.id
					})
				}

			},
			getlist(v) {
				this.show = v;
				// this.listdata = []
				// this.mescroll.resetUpScroll()
				this.loadData(1)
			},
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.qunliao_close {
		width: 70rpx;
		height: 70rpx;
		margin: 116rpx auto;
		display: block;
		/* position: absolute; */
	}

	.pop>image:nth-of-type(1) {
		width: 399rpx;
		height: 399rpx;
		margin: 258rpx auto 0;
		display: block;
	}

	.pop {
		width: 640rpx;
		height: 743rpx;
		padding-top: 1rpx;
		position: relative;
	}

	.image3 {
		width: 95rpx;
		height: 36rpx;
		position: absolute;
		top: 29rpx;
		right: 28rpx;
	}

	.image2 {
		width: 95rpx;
		height: 39rpx;
		position: absolute;
		top: 73rpx;
		right: 28rpx;
	}

	.image1 {
		width: 82rpx;
		height: 37rpx;
		position: absolute;
		top: 18rpx;
		left: 20rpx;
	}

	.huodong_b {
		width: 356rpx;
		height: 120rpx;
		margin-top: 20rpx;
	}

	.huodong_t {
		width: 233rpx;
		height: 118rpx;
	}

	.huodong {
		display: flex;
		align-items: center;
		padding: 40rpx 0;

		.item {
			flex: 1;
			text-align: center;

			.item_img {
				image {
					width: 88rpx;
					height: 88rpx;
				}
			}

			.item_text {
				font-size: 24rpx;
				color: #FFFFFF;
			}
		}
	}

	swiper {
		width: 100%;
		/* height: 38rpx; */
		display: flex;
		align-items: center;
		pointer-events: auto;
	}


	.gonggao {
		width: 750rpx;
		height: 300rpx;
		border-radius: 39rpx;
		margin: 0rpx auto;
		overflow: hidden;
		display: flex;
		align-items: center;
		padding: 0 20rpx;
		box-sizing: border-box;
		/* position: relative; */
		position: absolute;
		top: 330rpx;
		z-index: 16;
		pointer-events: none;
	}

	.yh_bg {
		width: 750rpx;
		height: 660rpx;
		/* border-radius: 20rpx; */
		/* margin: 0 auto; */
		/* margin: 5rpx; */
		/* margin-top: 15rpx; */
	}

	.swiper-box {
		width: 750rpx;
		height: 660rpx;
		margin: 0rpx auto;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.fixed {
		/* background: linear-gradient(0deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 1)); */
		width: 750rpx;
		height: 230rpx;
		padding: 30rpx;
		box-sizing: border-box;
		position: fixed;
		/* #ifdef MP */
		top: 0;
		/* #endif */
		/* #ifndef MP */
		top: 0rpx;
		/* #endif */
		z-index: 15;
	}

	.flex_center {
		align-items: center;
	}

	.header-left-title {
		/* width: 191rpx; */
		// height: 69rpx;
		// font-weight: bold;
		// color: #FFFFFF;
		font-size: 40rpx;
		font-weight: bold;
		background: linear-gradient(0deg, #B18DD6 0%, #FFFFFF 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		font-family: 'pangmen';

		image {
			width: 50rpx;
			height: 50rpx;
			border-radius: 50%;
		}
	}

	.content {
		background: #09081C;
		width: 100vw;
		/* height: 100vh; */
		box-sizing: border-box;
		position: relative;
		background-attachment: fixed;
		position: relative;
	}

	.title_ipt {
		display: flex;
		align-items: center;
		margin: 20rpx 0;
		margin-left: 30rpx;
		border-radius: 30rpx;
		padding-left: 30rpx;
		width: 350rpx;
		height: 60rpx;
		background: rgba(#999999, 0.6);
		border-radius: 29rpx;
		box-sizing: border-box;
	}

	.title_ipt>image {
		width: 33rpx;
		height: 33rpx;
	}

	.title_ipt>input {
		width: 90%;
		height: 60rpx;
		box-sizing: border-box;
		border-radius: 105rpx;
		font-size: 28rpx;
		line-height: 60rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(255, 255, 255, 0.6);
		padding-left: 20rpx;
	}

	.qiehuan {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 690rpx;
		margin: 0 auto;
		box-sizing: border-box;
		/* font-family: 'zcq'; */
		font-weight: bold;
	}

	.qiehuan_line {
		margin: -10rpx auto;
		width: 50rpx;
		height: 20rpx;
		border-bottom: 4rpx solid #E68EFF;
		border-radius: 2rpx;
	}


	.qiehuan>view {
		flex: 1;
		text-align: center;
	}

	.wzs {
		font-size: 32rpx;
		color: rgba(255, 255, 255, 0.6);
	}

	.xzs {
		font-size: 34rpx;
		background: linear-gradient(0deg, #B75AFF 0%, #E7CBFF 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
	}

	.qbt_con {
		margin: 0rpx auto;
		width: 710rpx;
		padding-bottom: 100rpx;
		// display: flex;
		// justify-content: space-between;
		// flex-wrap: wrap;
		font-size: 24rpx;
	}

	.qbt_con_item {
		margin-top: 30rpx;
		border-radius: 20rpx 20rpx 0 0;
		width: 100%;
		height: 400rpx;
		position: relative;
		padding: 0rpx 20rpx;
		box-sizing: border-box;

		.item_shang {
			position: absolute;
			right: 30rpx;
			top: 60rpx;
			font-size: 24rpx;
			font-weight: bold;
			background-color: rgba(#000000, 0.8);
			padding: 10rpx 25rpx;
			border-radius: 100rpx;

			text {
				background: linear-gradient(0deg, #B75AFF 0%, #E7CBFF 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
		}

		.item_title {
			width: 450rpx;
			color: #FFFFFF;
			font-size: 24rpx;
			font-weight: 400;
			line-height: 50rpx;
			margin-left: 30rpx;
			font-family: SourceHanSansSC;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.item_img {
			text-align: center;
			width: 100%;

			image {
				width: 100%;
				height: 280rpx;
			}
		}

		.item_info {
			color: #FFFFFF;
			display: flex;
			align-items: center;
			height: 70rpx;
			position: absolute;
			bottom: 20rpx;
			left: 2%;
			width: 96%;

			image {
				width: 30rpx;
				height: 30rpx;
			}

			.item_info_left {
				font-size: 24rpx;
				margin-left: 30rpx;
				margin-top: 10rpx;
			}

			.item_info_img {
				display: flex;
				align-items: center;
				margin-top: 10rpx;

				image {
					width: 22rpx;
					height: 24rpx;
					margin-left: 10rpx;
				}
			}

			.item_info_text {
				margin-left: 30rpx;
				margin-top: 10rpx;
				flex: 1;
			}

			.item_info_price {
				font-size: 20rpx;
				margin-right: 25rpx;

				.item_info_price_text {
					font-size: 28rpx;
				}
			}
		}
	}

	.list_1 {
		width: 290rpx;
		height: 290rpx;
		border-radius: 10rpx 10rpx 0rpx 0rpx;
		/* position: relative; */
		display: flex;
		align-items: center;
		justify-content: center;
		overflow: hidden;
	}

	.list_1>image {
		width: 290rpx;
		height: 290rpx;
		/* position: absolute; */
		border-radius: 10rpx 10rpx 0 0;
		/* margin-left: 4rpx; */
		margin-top: 5rpx;
	}

	.list_2 {
		padding: 20rpx 0;
		border-radius: 0rpx 0rpx 10rpx 10rpx;
		color: #FFFFFF;
	}


	.qbt_con_item_3 {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 4rpx;
		color: #C95C10;
	}

	.qbt_con_item_price {
		color: #FFFFFF;
		margin-left: 20rpx;
		opacity: .4;
		display: flex;
		align-items: center;
	}

	.qbt_con_item_price>image {
		width: 30rpx;
		height: 30rpx;
		margin-left: 10rpx;
	}

	.redu {
		width: 290rpx;
		height: 46rpx;
		margin-top: 10rpx;
		display: flex;
		align-items: center;
	}

	.redu>image {
		width: 32rpx;
		height: 32rpx;
		border: 2rpx solid rgba(255, 255, 255, 0.8);
		border-radius: 50%;
	}

	/* .redu>text {} */
</style>